<?php
include 'connect_db.php';
if (!checkLoggedin())
{
  header('Location: login.php');
}

require 'mail/class.phpmailer.php';
$mail  = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
//GMAIL config
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "ssl";                 // sets the prefix to the server
	$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
	$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
	$mail->Username   = "renttracker123@gmail.com";  // GMAIL username
	$mail->Password   = "bojiangjin";            // GMAIL password
//End Gmail

$message = trim(nl2br($_POST['message'])).'<br><br>Please click to <a href="http://localhost/web-sys-project/join.php?'.'house_id='.$_POST['house_id'].'">Join</a>!<br><br>'.$_POST['firstname'].' '.$_POST['lastname'];

$mail->From       = "admin@rentracker.com";
$mail->FromName   = "RenTracker";
$mail->Subject    = $_POST['firstname']." ".$_POST['lastname']." would like to invite you to join ".$_POST['house_name']." on RenTracker.com";
$mail->MsgHTML($message);
$mail->AddAddress($_POST['email']);
$mail->IsHTML(true); // send as HTML

if(!$mail->Send())
{//to see if we return a message or a value bolean
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else 
echo "Message sent!";

header('Location: index.php');//a user not belong to this house
